import { Module } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { APP_GUARD } from "@nestjs/core";
import { JwtModule } from "@nestjs/jwt";
import { MenuModule } from "@/modules/system/menu/menu.module";
import { PermModule } from "@/modules/system/permission/perm.module";
import { UserModule } from "@/modules/system/user/user.module";
import { AuthController } from "./auth.controller";
import { AuthGuard } from "./auth.guard";
import { AuthService } from "./auth.service";

@Module({
    imports: [
        UserModule,
        MenuModule,
        PermModule,
        JwtModule.registerAsync({
            useFactory: async (configService: ConfigService) => ({
                secret: configService.get<string>("JWT_SECRET"),
            }),
            inject: [ConfigService],
        }),
    ],
    providers: [
        AuthService,
        {
            provide: APP_GUARD,
            useClass: AuthGuard, // 启用全局身份验证守卫
        },
    ],
    controllers: [AuthController],
})
export class AuthModule {}
